'''
作业，修复BUG:已经修改

http://127.0.0.1:5000/chapter/?url=http://www.x23us.us/39_39642/16556658.html&host=http://www.x23us.us

以上链接的bug:

1、上一页报错
2、没有返回主目录按钮



作业修复BUG:已经修改

http://127.0.0.1:5000/book_info/?url=http://www.xbiquge.la/15/15159/&host=http://www.xbiquge.la

只显示10章节


作业修复bug:修复

http://127.0.0.1:5000/chapter/?url=http://www.xbiquge.la/15/15159/6873431.html&host=http://www.xbiquge.la

下一页报错，上一页报错

作业修复bug:修复

http://127.0.0.1:5000/search/?keyworld=%E5%A4%A7&host=http%3A%2F%2Fwww.zggdwx.com

搜索到的结果为什么都不能点

作业修复bug:修复

http://127.0.0.1:5000/book_info/?url=http://www.zggdwx.com/gongyang.html&host=http%3A%2F%2Fwww.zggdwx.com

报错，无法渲染

'''
from flask import Flask, request, render_template
from spiders.novel import Novel

app = Flask(__name__)

@app.route('/')#index页面
def index():

    return render_template("index.html")

@app.route('/book_info/')#小说目录信息

def api_book_info():
    '''
    http://127.0.0.1:5000/book_info/?url=http://www.x23us.us/39_39642/&host=http://www.x23us.us

    '''
    get_info = request.args

    host = get_info.get('host')
    url = get_info.get('url')

    if host == None or url == None:

        return "请确认你参数"

    result_dict = Novel(host).get_book_info(url)

    # return str(result_dict)

    return render_template('book_info.html', result_dict = result_dict)
@app.route('/chapter/')#下午作业

def api_chapter_info():#小说网站章节信息接口
    '''
    如下链接，传两参数，返回对应章节信息的json数据格式
    http://127.0.0.1:5000/api/chapter/?url=http://www.x23us.us/39_39642/19553679.html&host=http://www.x23us.us

    '''
    get_info = request.args
    host = get_info.get("host")
    url = get_info.get("url")
    if host == None or url == None:
        return "请检擦你参数"

    result_dict = Novel(host).get_chapter_info(url)
    # return result_info

    return render_template("chapter_info.html", result_dict = result_dict)


@app.route('/search/')#小说网站查询接口
def api_search_info():
    '''
    http://127.0.0.1:5000/search/?keyworld=大主宰&host=http://www.x23us.us

    '''
    get_info = request.args
    host = get_info.get("host")
    keyword = get_info.get("keyworld")
    if host == None or keyword == None:
        return "请检擦你参数"
    search_info = Novel(host).get_search_info(keyword)

    return render_template('search_info.html',result_dict = search_info)



if __name__ == '__main__':
    
    app.run(debug = True)